package org.budo.datasource.routing.impl;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.budo.datasource.routing.connection.BudoRoutingConnection;
import org.budo.datasource.routing.parser.Parser;
import org.budo.datasource.routing.parser.jsqlparser.JSqlParser;
import org.budo.datasource.routing.router.Router;
import org.budo.datasource.routing.router.impl.DefaultRouter;

/**
 * @author lmw
 */
public abstract class AbstractBudoRoutingDataSource extends NotSupportedBudoRoutingDataSource {
    private DataSource defaultDataSource;

    private Parser parser = new JSqlParser();

    private Router router = new DefaultRouter();

    public Parser getParser() {
        return parser;
    }

    public void setParser(Parser parser) {
        this.parser = parser;
    }

    public Router getRouter() {
        return router;
    }

    public void setRouter(Router router) {
        this.router = router;
    }

    public DataSource getDefaultDataSource() {
        return defaultDataSource;
    }

    public void setDefaultDataSource(DataSource defaultDataSource) {
        this.defaultDataSource = defaultDataSource;
    }

    @Override
    public Connection getConnection() throws SQLException {
        Connection defaultConnection = this.getDefaultDataSource().getConnection();
        return new BudoRoutingConnection(defaultConnection, this);
    }
}